#include "LinkQueue.h"
#include "LinkStack.h"
#include <iostream>
#include "car.h"
const int StopSize=3;
class CarStop
{

public:
    
    CarStop(const int &size):StopSize(size){}
    void ComeCar();
    void  LeaveCar();
    void   Display();

private:
    LinkStack stop;//停车场
    LinkQueue pavement;//便道
    const int StopSize;

};
void CarStop::ComeCar()
{
    std::cout<<"输入车牌号:";
    Car*c=new Car;
    std::cin>>c->name;
    std::cout<<"输入到达时间：";
    std::cin>>c->ArriveTime;
    if(stop.Size()==StopSize)
    {
        std::cout<<"停车场已满，|"<<c->name<<"|停在了便道上\n";
        pavement.Push(c);
    }
    else
    {
        std::cout<<"还有车位，|"<<c->name<<"|停在停车场\n";
        stop.Push(c);
    }

}

void CarStop::LeaveCar()
{
    std::cout<<"请输入离厂车辆:";
    std::string leavename;
    std::cin>>leavename;
    LinkStack tempstop;
    int leavetime=0;
    while (stop.IsEmpty()==false)
    {
        Car*c=(Car*)stop.GetTop();
        if (c->name==leavename)
        {
            std::cout<<"请输入车辆的离厂时间：";
            std::cin>>c->LeaveTime;
            leavetime=c->LeaveTime;
            int money=(c->LeaveTime-c->ArriveTime)*5;
            std::cout<<"车辆|"<<c->name<<"|于|"<<c->LeaveTime<<"|离开停车场，费用是|"
            <<money<<"|"<<std::endl;
            delete c;
            stop.Pop();
            break;
        }
        tempstop.Pop();
        tempstop.Push(c);
    }
    
while (tempstop.IsEmpty()==false)
{
    stop.Push(tempstop.GetTop());
    tempstop.Pop();
}
//
if(stop.Size()<StopSize&&pavement.IsEmpty()==false)
{
    Car*c=(Car*)pavement.GetFront();
    std::cout<<"便道上的车|"<<c->name<<"|在"<<c->ArriveTime<<"进入停车场\n";
    pavement.Pop();
    stop.Push(c);



}


}

void CarStop::Display()
{
    LinkStack tempstop;
    while (stop.IsEmpty()==false)
    {
        tempstop.Push(stop.GetTop());
        stop.Pop();
    }
    
    while (stop.IsEmpty()==false)
    {
        Car*c=(Car*)tempstop.GetTop();
        std::cout<<"|🛴|"<<c->name<<std::endl;
        stop.Pop();
        stop.Push(c);
    }
    for (int i = 0; i < pavement.Size(); i++)
    {
        std::cout<<"____";
    }
    
    LinkQueue tempPavement;
    while (pavement.IsEmpty()==false)
    {
        Car*c=(Car*)pavement.GetFront();
        std::cout<<"🛴"<<c->name<<" ";
        pavement.Pop();
        tempPavement.Push(c);
    }
    std::cout<<std::endl;
    while (tempPavement.IsEmpty()==false)
    {
        pavement.Push(tempPavement.GetFront());
        tempPavement.Pop();
    }
    for (int i = 0; i < pavement.Size(); i++)
    {
        std::cout<<"____";
        std::cout<<std::endl;
    }
    
    


}

int main()
{
    CarStop s(3);
    while (1)
    {
       s.Display();
       std::cout<<"1.来车\n";
       std::cout<<"2.去车\n";
       std::cout<<"3.退出\n";
        int choice=-1;
        std::cin>>choice;
        switch (choice)
        {
        case 1:
            s.ComeCar();
            s.Display();
            break;
        case 2:
            s.LeaveCar();
            s.Display();
            break;
        case 3:
            exit(-1);
            break;        

        default :
            break;
        }





    }
    


return 0;
}














